package com.example.springbootnetty;

import com.corundumstudio.socketio.*;
import com.corundumstudio.socketio.annotation.SpringAnnotationScanner;
import com.corundumstudio.socketio.listener.DataListener;
import com.corundumstudio.socketio.listener.ExceptionListener;
import com.example.springbootnetty.socket.ChatHandler;
import com.example.springbootnetty.socket.ChatObject;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.util.List;
import java.util.Map;

@SpringBootApplication
public class SpringBootNettyApplication {
//	@Value("${wss.server.port}")
	private int port = 9094;

//	@Value("${wss.server.host}")
	private String host = "0.0.0.0";



	public static void main(String[] args) {
		SpringApplication.run(SpringBootNettyApplication.class, args);
	}

	@Bean
	public SocketIOServer socketServer(){
		Configuration configuration = new Configuration();
		configuration.setPort(port);
		configuration.setHostname(host);
		configuration.setAuthorizationListener(new AuthorizationListener() {
			@Override
			public boolean isAuthorized(HandshakeData data) {
				return true;
			}
		});
        SocketIOServer socketIOServer = new SocketIOServer(configuration);
		return socketIOServer;
	}


	@Bean
	public SpringAnnotationScanner springAnnotationScanner(SocketIOServer ssrv) {
		return new SpringAnnotationScanner(ssrv);
	}
}
